<template>
	<view class="mainbgc">
		<header-top :messageInfo="{typeFlag:true,message:'出库单查询',liner:false}">
			<view class="rightmsg" slot="rightmsg">
				<view class="rightmsg_content flexleft" @click="show=true">筛选</view>
			</view>
		</header-top>
		<view class="mainpadding" style="padding-bottom: 200rpx;">
			<view class="flexbetween">
				<input class="input-text" type="text" placeholder="请输入供应商/客户/仓库/经办人" v-model="keywords" @confirm="init" confirm-type="search">
				<view class="sousuo" @click="init()">搜索</view>
			</view>
			<view class="flexcenter" v-if="!list.total">
				<view class="placeholderimage"></view>
			</view>
			<view class="mainpadding_top  ffffff radius flexleft" v-for="item in list.data" :key="item.id">
				<view class="littleimg">
					<!-- 选中 -->
					<view class="selecticon" v-show="item.is_check" @click.stop="changeCheck(item)">
						<image src="@/static/image/system/dui.png" mode=""></image>
					</view>
					<!-- 未选中 -->
					<view class="noselecticon" v-show="!item.is_check" @click.stop="changeCheck(item)"></view>
				</view>
				<view class="bigimg" @click="chukudetail(item.id,113)">
					<view class="flexbetween">
						<view class="flexleft">
							<view class="titletext">{{item.order_no}}</view>
						</view>
						<view class="wlable radius" v-show="item.status==10">待出库</view>
						<view class="green radius" v-show="item.status==20">已出库</view>
						<view class="hlable radius" v-show="item.status==30">出库拒绝</view>
					</view>
					<view class="needbottline">
						<view class="flexbetween margin_top2 smalltext">
							<view>仓库：{{item.warehouse.name}}</view>
							<view>{{item.createtime_text}}</view>
						</view>
						<view class="flexleft margin_top2 smalltext" v-if="item.staff">
							<view class="">经办人：{{item.staff.username}}</view>
							<view class="dizhiimg" @click.stop="phone(item.staff.mobile)"></view>
						</view>
						<view class="flexleft margin_top2 titletext" v-if="item.supplier.id">
							<view class="">供应商：{{item.supplier.name}}
							<text class="smalltext">{{item.supplier.username}}</text></view>
							<view class="dizhiimg" @click.stop="phone(item.supplier.mobile)"></view>
						</view>
						<view class="flexleft margin_top2 titletext" v-if="item.custom.id">
							<view class="">客户：{{item.custom.name}}
							<text class="smalltext">{{item.custom.username}}</text></view>
							<view class="dizhiimg" @click.stop="phone(item.custom.mobile)"></view>
						</view>
						<view class="flexbetween margin_top2 smalltext">
							<view class="">出库类型：</view>
							<view class="" v-show="item.type==1">采购退货出库单</view>
							<view class="" v-show="item.type==2">销售单出库单</view>
							<view class="" v-show="item.type==3">其他出库单</view>
						</view>
						<view class="margin_top2 ywy nostrongtext yihang" v-show="item.notes">备注：{{item.notes}}</view>
						<view class="flexleft margin_top2 smalltext" v-if="item.send_staffinfo"  @click.stop="phone(item.send_staffinfo.mobile)">
							<view>司机：{{item.send_staffinfo.username}}</view>
							<view>{{item.send_staffinfo.mobile}}</view>
							<view class="dizhiimg"></view>
						</view>
					</view>
					<view class="strongtext margin_top2">共计：{{item.goods_zl_num}}种 {{item.goods_num}}件</view>
					<view class="flexright margin_top2">
						<view class="xiaolankuang flexbetween margin_left2" v-if="item.status==10" style="border-color: #1ED76D;" 
							@click.stop="examine(item.id,112)">
							<u-icon name="android-fill" color="#1ED76D" size="16"></u-icon>
							<view class="xiaolan margin_left1"  style="color: #1ED76D;">审核</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="pagebottom flexbetween">
			<view class="pagebottom_left flexcenter" @click="changeAllCheck">
				<view class="">
					<view class="selecticon" v-show="list.is_all">
						<image src="@/static/image/system/dui.png" mode=""></image>
					</view>
					<view class="noselecticon" v-show="!list.is_all"></view>
				</view>
				<view><text class="allchange">全选</text></view>
			</view>
			<view class="flexaround">
				<text class="pagebottom_fahuo" @click="submit(115)">统计</text>
			</view>
		</view>
		<u-popup round="20" :show="show" @close="show=false">
			<view class="mainpadding">
				<view class="flexcenter">
					<view class="titletext">筛选</view>
				</view>
				<view class="strongtext margin_top">时间</view>
				<view class="flexleft" style="flex-wrap: wrap;">
					<view class="screenbox flexcenter" v-for="(item,index) in datelist" :key="item.id"
						@click="change(item.name,index)">
						<view :class="currents == index? 'itemscreenfocus margin_top':'itemscreen margin_top'">
							{{item.name}}
						</view>
					</view>
				</view>
				<view class="strongtext margin_top">自定义时间</view>
				<view class="flexleft">
					<view class="inputscreenbox flexcenter" @click="shows=true">
						<input class="itemscreen margin_top" type="text" disabled v-model="start">
					</view>
					<view class="zwscreenbox flexcenter">
						<view class="strongtext">-</view>
					</view>
					<view class="inputscreenbox flexcenter" @click="showss=true">
						<input class="itemscreen margin_top" type="text" disabled v-model="end">
					</view>
				</view>
				<view class="strongtext margin_top">状态</view>
				<view class="flexleft" style="flex-wrap: wrap;">
					<view class="screenbox flexcenter" v-for="(item,index) in statuslist" :key="item.id"
						@click="changestatus(item.id)">
						<view :class="currentstatus == item.id?'itemscreenfocus margin_top':'itemscreen margin_top'">
							{{item.name}}
						</view>
					</view>
				</view>
				<view class="itemscreens flexleft margin_top" @click="rukulxShow=true">
					<view class="strongtext minwidth">出库类型</view>
					<view class="rightscreen flexbetween">
						<input type="text" disabled="true" placeholder="选择出库类型" v-model="rukulx.name">
						<view class="righticon2"></view>
					</view>
				</view>
				<view class="flexbetween">
					<view class="surebtn reset flexcenter" style="margin-top: 60rpx;" @click="resetbtn">重置</view>
					<view class="surebtn flexcenter" style="margin-top: 60rpx;" @click="sureBtn">确认</view>
				</view>
			</view>
		</u-popup>
		<u-datetime-picker :show="shows" v-model="value1" mode="date" @confirm="confirm" @cancel="shows=false"
			 @close="shows=false"></u-datetime-picker>
		<u-datetime-picker :show="showss" v-model="value2" mode="date" @confirm="confirms" @cancel="showss=false"
			:minDate="mintime" @close="showss=false"></u-datetime-picker>
		<!-- 入库类型 -->
		<selectRuku :message="{rukulxShow:rukulxShow,type:2}" @rukuSure="rukuSure"></selectRuku>
		<u-modal :show="examineShow" title="审核" @confirm="examineConfirm" showCancelButton @cancel="examineShow=false">
			<view class="slot-content">
				<view class="mainpadding_top">
					<u-radio-group v-model="examineType" placement="row" circle>
						<u-radio activeColor="#0BBDCB" :customStyle="{marginRight: '30rpx'}" label="已出库" name="20"></u-radio>
						<u-radio activeColor="#0BBDCB" label="出库拒绝" name="30"></u-radio>
					</u-radio-group>
				</view>
			</view>
		</u-modal>
		<u-modal :show="examinenoteShow" title="输入审核备注" @confirm="examinenoteConfirm" showCancelButton @cancel="examinenoteShow=false">
			<view class="slot-content">
				<view class="mainpadding2">
					<textarea class="textarea mainpadding radius margin_top" placeholder="请输入审核备注信息"
						v-model="apply_notes"></textarea>
				</view>
			</view>
		</u-modal>
	</view>
</template>


<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				// 时间选择
				datelist: [{
						id: 1,
						name: '今日'
					},
					{
						id: 2,
						name: '昨日'
					},
					{
						id: 3,
						name: '本月'
					},
				],
				// 审核
				// 状态:10=待入库,20=已入库,30=入库拒绝,0=全部
				statuslist: [{
						id: 10,
						name: '待出库'
					},
					{
						id: 20,
						name: '已出库'
					},
					{
						id: 30,
						name: '入库拒绝'
					},
				],
				// 入库类型
				rukulxShow: false,
				rukulx: {
					name: "",
					id: ""
				},
				show: false, //筛选弹出层
				// 时间筛选
				currents: -1,
				currentstatus: -1,
				start: '开始时间',
				end: '结束时间',
				shows: false,
				showss: false,
				value1: Number(new Date()),
				value2: Number(new Date()),
				mintime: Number(new Date()),
				maxtime: Number(new Date()),
				keywords: "",
				page: 1,
				limit: 12,
				list: {
					data: []
				},
				// 审核
				examineType:"20",
				examineShow:false,
				examineId:"",
				examinenoteShow:false,
				apply_notes:"",
				
			}
		},
		onLoad(options) {
			if(options.type){
				this.currentstatus = options.type
			}
			this.init()
		},
		watch: {
			list: {
				deep: true,
				handler(newval) {
					let num = 0
					this.list.data.forEach(item => {
						if (item.is_check) {
							num++
						}
					})
					if (this.list.data.length == num) {
						this.list.is_all = true
					} else {
						this.list.is_all = false
					}
				}
			}
		},
		methods: {
			examine(id,qxpdid) {
				if (!httpRequest.qxpd(qxpdid, this.$store.state.userInfo.ability_rule_ids)) {
					return false
				}
				this.examineId = id
				this.examineShow = true
			},
			examineConfirm(){
				this.examineShow = false
				this.examinenoteShow = true
			},
			examinenoteConfirm(){
				this.examinenoteShow = false
				// if(this.apply_notes==""){
				// 	httpRequest.toast("请输入审核备注")
				// 	return false
				// }
				httpRequest.request('/dhtapi/Outboundorder/applyOutboundOrder', 'GET', {
					id: this.examineId,
					status: this.examineType,
					apply_notes:this.apply_notes
				}, false, false, true).then(res => {
					httpRequest.toast(res.msg)
					console.log(res,"错误西悉尼");
					if(res.code==1){
						this.init()
					}
				})
			},
			// 统计
			submit(qxpdid) {
				if (!httpRequest.qxpd(qxpdid, this.$store.state.userInfo.ability_rule_ids)) {
					return false
				}
				let arr = []
				this.list.data.forEach(item => {
					if (item.is_check) {
						arr.push(item.id)
					}
				})
				if (arr.length == 0) {
					httpRequest.toast("请选择需要汇总的数据")
					return
				}
				let data = {
					type: 7, //出库单
					arr: arr
				}
				uni.navigateTo({
					url: '/pages/workbench/kucun/chukudtjmx?data=' + encodeURIComponent(JSON.stringify(data))
				})
			},
			// 单选
			changeCheck(item) {
				item.is_check = item.is_check ? false : true
			},
			// 多选
			changeAllCheck() {
				if (this.list.is_all) {
					this.list.is_all = false
					this.list.data.forEach(item => {
						item.is_check = false
					})
				} else {
					this.list.is_all = true
					this.list.data.forEach(item => {
						item.is_check = true
					})
				}
			},
			jumpurl(url) {
				uni.navigateTo({
					url: url
				})
			},
			init(isPage, page) {
				let _this = this;
				httpRequest.request('/dhtapi/Outboundorder/index', 'GET', {
					page: page || 1,
					limit: _this.limit,
					keywords: this.keywords,
					start_time: this.start == '开始时间' ? '' : this.start, //开始日期
					end_time: this.end == '结束时间' ? '' : this.end, //结束日期
					status: this.currentstatus == -1 ? "" : this.currentstatus, //审核状态0=未审核,1=已审核
					type: this.rukulx.id,
				}, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = _this.list;
						this.$set(res.data, 'is_all', false)
						res.data.data.forEach(item => {
							this.$set(item, 'is_check', false)
						})
						if (isPage == true) {
							_this.list.data = dataList.data.concat(resList.data);
						} else {
							_this.list = resList
							_this.list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.list;
				let page = _this.page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.page = page;
				_this.init(true, page);
			},
			// 入库类型确定
			rukuSure(e) {
				this.rukulxShow = false
				if (e) {
					this.rukulx.id = e.value[0].id
					this.rukulx.name = e.value[0].name
				}
			},
			date(timer) {
				var date = new Date(timer); //当前时间
				var year = date.getFullYear() //返回指定日期的年份
				var month = repair(date.getMonth() + 1); //月
				var day = repair(date.getDate()); //日
				var curTime = year + "-" + month + "-" + day

				function repair(i) {
					if (i >= 0 && i <= 9) {
						return "0" + i;
					} else {
						return i;
					}
				}
				return curTime
			},
			confirm(e) {
				console.log(e);
				this.shows = false;
				this.show = true;
				this.end = '结束时间';
				this.mintime = e.value;
				this.start = this.date(e.value);
				this.currents = -1;
			},
			confirms(e) {
				this.showss = false;
				this.show = true;
				this.maxtime = e.value;
				this.end = this.date(e.value);
				this.currents = -1;
			},
			changestatus(index) {
				this.currentstatus = index;
			},
			change(name, index) {
				if (name == "今日") {
					this.start = this.riqi(0);
					this.end = this.riqi(0);
				} else if (name == "昨日") {
					this.start = this.riqi(-1);
					this.end = this.riqi(-1);
				} else if (name == "本月") {
					this.start = this.benyue();
					this.end = this.riqi(0);
				}
				this.currents = index;
			},
			// 昨天“-1”今天“0”明天“1”
			riqi(day) {
				let dd = new Date();
				dd.setDate(dd.getDate() + day);
				let y = dd.getFullYear();
				let m = dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
				let d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
				return y + "-" + m + "-" + d;
			},
			// 本月第一天
			benyue() {
				let y = new Date().getFullYear(); //获取年份
				let m = new Date().getMonth() + 1; //获取月份
				let d = '01'
				m = m < 10 ? '0' + m : m; //月份补 0
				return [y, m, d].join("-")
			},
			// 重置
			resetbtn() {
				this.currentstatus = -1
				this.currents = -1
				this.start = "开始时间"
				this.end = "结束时间"
				this.cangku.id = ""
				this.cangku.name = ""
				this.rukulx.name = ""
				this.rukulx.id = ""
				this.init()
				this.show = false
			},
			sureBtn() {
				this.show = false
				this.init()
			},
			chukudetail(id,qxpdid) {
				if (!httpRequest.qxpd(qxpdid, this.$store.state.userInfo.ability_rule_ids)) {
					return false
				}
				uni.navigateTo({
					url: "/pages/workbench/kucun/chukudxq?id=" + id
				})
			},
			phone(p) {
				uni.makePhoneCall({
					phoneNumber: p.toString()
				}).catch((e) => {
					// console.log(e)  //用catch(e)来捕获错误{makePhoneCall:fail cancel}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.textarea {
		box-sizing: border-box;
		background-color: #F8F8F8;
		height: 180rpx;
	}
	.pagebottom {

		width: 100%;

		padding: 30rpx 30rpx 40rpx;

		box-sizing: border-box;

		background-color: #fff;

		position: fixed;

		bottom: 0;

	}

	.pagebottom_left {
		margin-left: 40rpx;
	}

	.pagebottom_right {
		margin-right: 100rpx;
	}

	.pagebottom_fahuo {
		color: #fff;
		padding: 10rpx 80rpx;
		font-size: 28rpx;
		border-radius: 30rpx;
		background-color: #0BBDCB;
		background-color: #00B855;
	}

	.allchange {
		margin-left: 20rpx;
	}

	.searchinput {
		width: 80%;
		padding: 20rpx 30rpx;
		border-radius: 50rpx;
		background-color: #f0f0f0;
	}

	// 内容
	// 审核状态
	.hlable {
		padding: 6rpx 14rpx;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #ff0000;
		line-height: 28rpx;
		background-color: rgba(253, 4, 4, .1);
	}

	.input-text {
		width: 80%;
		padding: 18rpx 0 18rpx 32rpx;
		background: rgba(153, 153, 153, .1);
		border-radius: 50rpx 50rpx 50rpx 50rpx;
		font-size: 26rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.wlable {
		padding: 6rpx 14rpx;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #F3AD3D;
		line-height: 28rpx;
		background-color: #fef7ec;
	}

	.green {
		padding: 6rpx 14rpx;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #0ad161;
		line-height: 28rpx;
		background-color: rgba(10, 209, 97, .1);
	}

	.needbottline {
		padding-bottom: 30rpx;
		border-bottom: 1rpx solid rgba(153, 153, 153, 0.06);
	}

	.smalltext {
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	// 审核状态
	.wlable {
		padding: 6rpx 14rpx;
		font-size: 24rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #F3AD3D;
		line-height: 28rpx;
		background-color: #fef7ec;
	}

	.inputscreenbox {
		width: 40%;

		input {
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			border-radius: 50rpx;
			font-size: 28rpx;
			font-family: PingFang SC-Medium, PingFang SC;
			font-weight: 500;
			color: #333;
			background-color: #f7f9fa;
		}
	}

	.zwscreenbox {
		width: 20%;
		line-height: 80rpx;
	}

	.itemscreenfocus {
		width: 200rpx;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		border-radius: 50rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #0BBDCB;
		background-color: #e7f9fa;
	}

	// 筛选内容
	.screenbox {
		width: 33.33%;
	}

	.itemscreen {
		width: 200rpx;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		border-radius: 50rpx;
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		color: #999999;
		background-color: #f7f9fa;
	}

	.surebtn {
		width: 45%;
	}

	.reset {
		background: #ebb563;
	}

	// 选择
	.rightscreen {
		width: 100%;
	}

	.itemscreens {
		font-size: 28rpx;
		font-family: PingFang SC-Medium, PingFang SC;
		font-weight: 500;
		padding-bottom: 20rpx;
	}

	.minwidth {
		min-width: 130rpx;
	}
</style>